#ifndef _DEV_H
#define _DEV_H

#include "core/dev_cfg.h"
#include <stdint.h>

#ifdef __cplusplus
extern "C"{
#endif

#define DEVICE_TYPE_NONE        (0)
#define DEVICE_TYPE_UART        (1)    
#define DEVICE_TYPE_I2C         (2)     
#define DEVICE_TYPE_SPI         (3)     
#define DEVICE_TYPE_ADC         (4)     
#define DEVICE_TYPE_GPIO        (5)    
#define DEVICE_TYPE_TIMER       (6)   
#define DEVICE_TYPE_FLASH       (7)     

typedef struct device{
    const char *name;                  
    const struct device_ops *ops;      
    void *private_data;                        
    void *user_data;                  
    const char *compat; 
    const int type;                 
    void *bus;                       
    void *drv;         
    struct device *next;           
}device_t;

typedef struct device_ops{
    int (*open)(device_t *dev, va_list args);
    int (*read)(device_t *dev, void *data, uint32_t len);
    int (*write)(device_t *dev, const void *data, uint32_t len);
    int (*ioctl)(device_t *dev, va_list args);
    int (*close)(device_t *dev);
}device_ops_t;

EXTERN DEVICE_PUBLIC(void) device_table_info_print(void);
EXTERN DEVICE_PUBLIC(int) device_register(device_t *dev, void *bus);
EXTERN DEVICE_PUBLIC(int) device_unregister(device_t *dev);
EXTERN DEVICE_PUBLIC(device_t *) device_find(const char *name);
EXTERN DEVICE_PUBLIC(int) device_open(device_t *dev, ...);
EXTERN DEVICE_PUBLIC(int) device_close(device_t *dev);
EXTERN DEVICE_PUBLIC(int) device_read(device_t *dev, void *data, uint32_t len);
EXTERN DEVICE_PUBLIC(int) device_write(device_t *dev, const void *data, uint32_t len);
EXTERN DEVICE_PUBLIC(int) device_ioctl(device_t *dev, ...);

#ifdef __cplusplus
}
#endif

#endif
